<template>
  <div class="teacher-detail">
    <div class="container">
      <!-- 讲师基本信息 -->
      <div class="teacher-header">
        <div class="teacher-profile">
          <el-avatar :size="160" :src="teacher.avatar" />
          <div class="teacher-level" :class="teacher.level">{{ teacher.levelText }}</div>
        </div>
        <div class="teacher-info">
          <h1 class="teacher-name">{{ teacher.name }}</h1>
          <p class="teacher-title">{{ teacher.title }}</p>
          <div class="teacher-stats">
            <div class="stat-item">
              <el-icon><Collection /></el-icon>
              <span>{{ teacher.courseCount }}门课程</span>
            </div>
            <div class="stat-item">
              <el-icon><User /></el-icon>
              <span>{{ teacher.studentCount }}名学生</span>
            </div>
            <div class="stat-item">
              <el-icon><Star /></el-icon>
              <span>{{ teacher.rating }}分</span>
            </div>
          </div>
          <div class="teacher-tags">
            <el-tag 
              v-for="tag in teacher.tags" 
              :key="tag" 
              size="small" 
              class="tag"
            >
              {{ tag }}
            </el-tag>
          </div>
        </div>
      </div>

      <!-- 讲师详细介绍 -->
      <el-card class="teacher-content">
        <template #header>
          <div class="card-header">
            <h2>讲师介绍</h2>
          </div>
        </template>
        <div class="content-section">
          <h3>个人简介</h3>
          <p>{{ teacher.description }}</p>
        </div>
        <div class="content-section">
          <h3>专业领域</h3>
          <p>{{ getFieldName(teacher.field) }}</p>
        </div>
        <div class="content-section">
          <h3>教学特色</h3>
          <ul>
            <li>深入浅出的讲解方式，让复杂的技术概念变得简单易懂</li>
            <li>丰富的实战经验，结合实际项目案例进行教学</li>
            <li>注重培养学生的实践能力和解决问题的能力</li>
            <li>持续关注技术发展趋势，及时更新教学内容</li>
          </ul>
        </div>
      </el-card>

      <!-- 讲师课程 -->
      <el-card class="teacher-courses">
        <template #header>
          <div class="card-header">
            <h2>主讲课程</h2>
          </div>
        </template>
        <div class="course-list">
          <el-card v-for="course in teacherCourses" :key="course.id" class="course-card" shadow="hover">
            <div class="course-content">
              <img :src="course.cover" :alt="course.title" class="course-cover">
              <div class="course-info">
                <h3 class="course-title">{{ course.title }}</h3>
                <p class="course-desc">{{ course.description }}</p>
                <div class="course-meta">
                  <span class="course-level">{{ course.level }}</span>
                  <span class="course-students">{{ course.studentCount }}人在学</span>
                  <span class="course-rating">{{ course.rating }}分</span>
                </div>
              </div>
            </div>
          </el-card>
        </div>
      </el-card>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { useRoute } from 'vue-router'
import { Collection, User, Star } from '@element-plus/icons-vue'

const route = useRoute()

// 讲师信息
const teacher = ref({
  name: route.query.name || '',
  title: route.query.title || '',
  avatar: route.query.avatar || '',
  description: route.query.description || '',
  level: route.query.level || '',
  levelText: route.query.levelText || '',
  courseCount: route.query.courseCount || 0,
  studentCount: route.query.studentCount || 0,
  rating: route.query.rating || 0,
  tags: JSON.parse(route.query.tags || '[]'),
  field: route.query.field || ''
})

// 专业领域映射
const fieldMap = {
  frontend: '前端开发',
  backend: '后端开发',
  mobile: '移动开发',
  ai: '人工智能',
  data: '数据科学',
  cloud: '云计算'
}

// 获取领域名称
const getFieldName = (field) => {
  return fieldMap[field] || field
}

// 讲师课程数据
const teacherCourses = ref([
  {
    id: 1,
    title: 'Vue3 从入门到精通',
    description: '全面讲解Vue3的核心概念和高级特性，带你掌握现代前端开发技术。',
    cover: 'https://picsum.photos/300/200?random=1',
    level: '中级',
    studentCount: 1234,
    rating: 4.9
  },
  {
    id: 2,
    title: 'React 18新特性详解',
    description: '深入解析React 18的新特性和最佳实践，提升你的React开发技能。',
    cover: 'https://picsum.photos/300/200?random=2',
    level: '高级',
    studentCount: 856,
    rating: 4.8
  },
  {
    id: 3,
    title: 'TypeScript实战教程',
    description: '从零开始学习TypeScript，掌握类型系统和高级类型的使用方法。',
    cover: 'https://picsum.photos/300/200?random=3',
    level: '中级',
    studentCount: 567,
    rating: 4.7
  }
])

onMounted(() => {
  // 这里可以添加获取讲师详细信息的逻辑
})
</script>

<style scoped>
.teacher-detail {
  padding: 20px;
  background-color: var(--bg-color);
  min-height: 100vh;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
}

.teacher-header {
  display: flex;
  gap: 40px;
  margin-bottom: 30px;
  padding: 30px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}

.teacher-profile {
  position: relative;
  flex-shrink: 0;
}

.teacher-level {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  padding: 4px 12px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: bold;
  color: white;
}

.teacher-level.senior {
  background-color: #67c23a;
}

.teacher-level.expert {
  background-color: #409eff;
}

.teacher-level.master {
  background-color: #f56c6c;
}

.teacher-info {
  flex: 1;
}

.teacher-name {
  margin: 0 0 8px;
  font-size: 32px;
  color: var(--text-primary);
  font-weight: bold;
}

.teacher-title {
  margin: 0 0 20px;
  font-size: 18px;
  color: var(--text-secondary);
}

.teacher-stats {
  display: flex;
  gap: 30px;
  margin-bottom: 20px;
}

.stat-item {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-light);
}

.teacher-tags {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.tag {
  border-radius: 4px;
}

.teacher-content,
.teacher-courses {
  margin-bottom: 30px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-header h2 {
  margin: 0;
  font-size: 20px;
  color: var(--text-primary);
}

.content-section {
  margin-bottom: 30px;
}

.content-section:last-child {
  margin-bottom: 0;
}

.content-section h3 {
  margin: 0 0 16px;
  font-size: 18px;
  color: var(--text-primary);
}

.content-section p {
  margin: 0;
  color: var(--text-secondary);
  line-height: 1.8;
}

.content-section ul {
  margin: 0;
  padding-left: 20px;
  color: var(--text-secondary);
  line-height: 1.8;
}

.course-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
}

.course-card {
  cursor: pointer;
  transition: all 0.3s ease;
}

.course-card:hover {
  transform: translateY(-5px);
}

.course-content {
  display: flex;
  flex-direction: column;
}

.course-cover {
  width: 100%;
  height: 160px;
  object-fit: cover;
  border-radius: 4px;
  margin-bottom: 12px;
}

.course-info {
  flex: 1;
}

.course-title {
  margin: 0 0 8px;
  font-size: 16px;
  color: var(--text-primary);
  font-weight: bold;
}

.course-desc {
  margin: 0 0 12px;
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.6;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.course-meta {
  display: flex;
  gap: 12px;
  font-size: 13px;
  color: var(--text-light);
}

.course-level {
  color: var(--el-color-primary);
}

.course-students {
  color: var(--text-secondary);
}

.course-rating {
  color: #f7ba2a;
}
</style> 